package com.roc.util.constant;

import java.util.HashMap;

import org.apache.commons.lang3.StringUtils;

public enum MccGroup {
	MG_0("01","宾馆餐饮类"), 
	MG_1("02","产品批发类"),
	MG_2("03","房产保险类"),
	MG_3("04","汽车销售服务类"),
	MG_4("05","生活服务类"),
	MG_5("06","珠宝娱乐类"),
	MG_6("07","专项服务类");

	private String code;
	private String name;
	
	private MccGroup(String code,String name){
		this.code=code;
		this.name=name;
	}
	
	public static MccGroup valueOfCode(String code) {
		if (StringUtils.isBlank(code)) {
			throw new IllegalArgumentException("MccGroup " + code + " is blank");
		}
		for (MccGroup mt : values()) {
			if (mt.getCode().equals(code)) {
				return mt;
			}
		}
		throw new IllegalArgumentException("MccGroup " + code + " is not exist");
	}
	
	/**
	 * 通过ID获取中文名称
	 * @param code
	 * @return
	 */
	public static String getName(String code) {
		if (StringUtils.isBlank(code)) {
			return "";
		}
		for (MccGroup mt : values()) {
			if (mt.getCode().equals(code)) {
				return mt.getName();
			}
		}
		return "没有找到该类型";
	}
	
	/**
	 * 获取所有的枚举,以MAP返回
	 * @return
	 */
	public static HashMap<String,String> getAllEnumMap() {
		
		HashMap<String,String> map = new HashMap<String,String>();
		
		for (MccGroup mt : values()) {
			map.put(mt.getCode(), mt.getName());
		}
		
		return map;
		
	}
	
	public String getCode() {
		return code;
	}

	public String getName() {
		return name;
	}
}
